package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.BaseRole;
import com.briup.jz.bean.extend.BaseRoleExtend;
import com.briup.jz.service.BaseRoleService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description = "BaseRole相关接口")
@Validated
@RestController
@RequestMapping("/baseRole")
public class BaseRoleController {
	@Autowired
	private BaseRoleService baseRoleService;

	@ApiOperation(value = "查询所有角色类")
	@GetMapping("query")
	public Message query(String name) {
		List<BaseRole> list = baseRoleService.query(name);
		return MessageUtil.success(list);
	}

	@ApiOperation(value = "通过id删除角色")
	@GetMapping("deleteById")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键", paramType = "query", required = true), })
	public Message deleteById(@NotNull Long id) {
		baseRoleService.deleteById(id);
		return MessageUtil.success("删除成功");
	}

	@ApiOperation(value = "保存或更新角色信息")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键", paramType = "form"),
			@ApiImplicitParam(name = "name", value = "角色", paramType = "form", required = true), })
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(BaseRole baseRole) {
		baseRoleService.saveOrUpdate(baseRole);
		return MessageUtil.success("更新成功");
	}
	
	@GetMapping("selectRolePrivilege")
	@ApiOperation(value = "级联查询角色及权限")
	public Message selectRolePrivilege(String roleName ) {
		List<BaseRoleExtend> list=baseRoleService.selectRolePrivilege(roleName);
		return MessageUtil.success(list);
	}
}
